package br.com.infocruz.seam.crm.ejb.facade;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.Query;

import org.jboss.seam.annotations.Name;

import br.com.infocruz.seam.crm.ejb.jpa.JpaQuery;
import br.com.infocruz.seam.crm.ejb.model.EntityList;
import br.com.infocruz.seam.crm.ejb.model.User;

@Name("userFacade")
@Stateless
//@AuditLogger
//@Interceptors(AuditTrailInterceptor.class)
public class UserFacadeBean extends AbstractFacade<User> implements UserFacade {
	/**
	 * 
	 */
	private static final long serialVersionUID = -8612986454426063416L;

	public UserFacadeBean() {
		super(User.class);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<User> findByUserName(String userName) {
		Query query = createJpaNamedQuery("User.findByUserName");
		query.setParameter("userName", userName);
		return query.getResultList();
	}

	@Override
	public EntityList<User> findByUserName(String userName, Integer maxResults, Integer firstResult) {
		JpaQuery<User> query = createJpaNamedQuery("User.findByUserName", maxResults, firstResult);
		query.setParameter("userName", userName);
		return query.getEntityList();
	}
	
	@Override
	public EntityList<User> findByUserName(String userName, String orderDirection, String orderColumn) {
		JpaQuery<User> query = createJpaNamedQuery("User.findByUserName", orderDirection, orderColumn);
		query.setParameter("userName", userName);
		return query.getEntityList();
	}
	
	@Override
	public EntityList<User> findByUserName(String userName, Integer maxResults, Integer firstResult, String orderDirection, String orderColumn) {
		JpaQuery<User> query = createJpaNamedQuery("User.findByUserName", maxResults, firstResult, orderDirection, orderColumn);
		query.setParameter("userName", userName);
		return query.getEntityList();
	}

}
